
<?php 
	$rootDoc = $_SERVER{'DOCUMENT_ROOT'};
	$path = "http://" . $_SERVER['SERVER_NAME'] . "/whmcs/modules/admin/shift_manager/";
	
	/*include function file*/
	$fileExist = file_exists($rootDoc."/whmcs/modules/admin/shift_manager/utilities/functions.php");	
	if($fileExist)		
		include_once $rootDoc."/whmcs/modules/admin/shift_manager/utilities/functions.php";
	else
		exit("<div>Function included was not found</div>");
	
	$user = $_SESSION['adminid'];
?>

<link href="<?php echo $path; ?>css/style.css" rel="stylesheet" type="text/css">		
<link href="<?php echo $path; ?>css/ui-lightness/jquery-ui-1.8.12.custom.css" rel="stylesheet" type="text/css">		
<script src="<?php echo $path; ?>js/jquery-1.6.js" type="text/javascript" language="javascript"></script>
<script src="<?php echo $path; ?>js/jquery-ui-1.8.12.custom.min.js" type="text/javascript" language="javascript"></script>
<script src="<?php echo $path; ?>js/caculator.js" type="text/javascript" language="javascript"></script>

		<?php
			$monthNames = Array("January",
								"February",
								"March",
								"April",
								"May",
								"June",
								"July",
								"August",
								"September",
								"October",
								"November",
								"December"
							);
							
			if (!isset($_REQUEST["month"]))
				$_REQUEST["month"] = date("n");
				
			if (!isset($_REQUEST["year"]))
				$_REQUEST["year"] = date("Y");

			$cMonth = $_REQUEST["month"];
			$cYear = $_REQUEST["year"];

			$prev_year = $cYear;
			$next_year = $cYear;
			$prev_month = $cMonth-1;
			$next_month = $cMonth+1;

			if ($prev_month == 0 ) {
				$prev_month = 12;
				$prev_year = $cYear - 1;
			}
			
			if ($next_month == 13 ) {
				$next_month = 1;
				$next_year = $cYear + 1;
			}

		?>
		
		<?php
			$currentMonth = (isset($_GET['month']))?$_GET['month']:date('n');
			$currentYear = (isset($_GET['year']))?$_GET['year']:date('Y');
		?>
	<form name="frmShiftManager" id="frmShiftManager" method="post" action="/whmcs/modules/admin/shift_manager/insertShiftAction.php?userid=<?php echo $_SESSION['adminid']; ?>" onSubmit="getAllCheckedBoxes()">
		<input type="submit" name="btnSaveShift" id="btnSaveShift" value="<?php echo (isNewShift($user, $currentMonth, $currentYear))?"Save":"Update"; ?>" <?php echo (isFullAdmin($_SESSION['id']))?"":"DISABLED"; ?> /><br/><br/>		
	<!-- generate calendar table-->
		<table width="100%">
			<tr align="center">
				<td bgcolor="#999999" style="color:#FFFFFF">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td width="50%" align="left">
								&nbsp;&nbsp;
								<a href="<?php echo $_SERVER["REQUEST_URI"] . "&month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a>&nbsp;&nbsp;	
							</td>
							<td width="50%" align="right">
								<a href="<?php echo $_SERVER["REQUEST_URI"] . "&month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a>&nbsp;&nbsp;	
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td align="center">
					<table width="100%" border="0" cellpadding="2" cellspacing="0" id="schedule_content">
						<tr align="center">
							<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
						</tr>
						<tr>							
							<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>Mon</strong></td>
							<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>Tue</strong></td>
							<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>Web</strong></td>
							<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>Thu</strong></td>
							<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>Fri</strong></td>
							<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>Sat</strong></td>
							<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>Sun</strong></td>
						</tr> 
						<?php 						
							$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
							$maxday = date("t",$timestamp);
							$thismonth = getdate ($timestamp);
							$startday = $thismonth['wday'];
							$wd = $startday+6;
							//echo date("D", time() + 24*60*60*3);
														
							$startday +=6;
							for ($i=0; $i<($maxday+$startday); $i++) {
								//get date by name 
								$date = date("D", time() + 24*60*60*$i);								
								
								//generate weeks (rows) of month
								if(($i % 7) == 0 ) echo "<tr>\n";
								//generate date (cell) of each weeks								
								if($i < $startday) echo "<td></td>\n";
								//genCheckOptionsBoxes
								else {
									$day = $i - $startday + 1;																	
									echo "<td align='center' valign='middle'><div class='weekDate'>". $day . "</div>" . genCheckOptionsBoxes(4,isWeekendDays($i),isHoliday($day, $currentMonth, $currentYear), $day). "</td>\n";
									$wd = ($wd<6)?++$wd:0;
								}
								
								//close row
								if(($i % 7) == 6 ) echo "</tr>\n";
							}
						?>
					</table>
				</td>
			</tr>
		</table> 
	
	<!-- include footer of shift -->
		<?php 
			 $fileExist = file_exists($rootDoc."/whmcs/modules/admin/shift_manager/shift_manager_detail.php");
			 
			 if($fileExist)
				include_once $rootDoc."/whmcs/modules/admin/shift_manager/shift_manager_detail.php";
			 else
				exit("<div>Function included was not found</div>");
		?>
		
		<input type="hidden" name="hdnMonth" value="<?php echo $currentMonth; ?>" />
		<input type="hidden" name="hdnYear" value="<?php echo $currentYear; ?>" />		
		<input type="submit" name="btnSaveShift" id="btnSaveShift" value="<?php echo (isNewShift($user, $currentMonth, $currentYear))?"Save":"Update"; ?>" <?php echo (isFullAdmin($_SESSION['id']))?"":"DISABLED"; ?> />		
	</form>		

<script>
	getCheckedShiftCoefficent();
</script>
